﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Aga.Informatizacion.Despachos
{
    public partial class MainForm : Form
    {
        private VerDespachos VerDespachosForm { get; set; }

        public MainForm()
        {
            InitializeComponent();

            CheckService();
        }

        private void CheckService()
        {
            using (var service = new UploadDataServiceClient())
            {
                bool online = false;
                try
                {
                    online = service.CheckService();
                }
                catch { }
                finally
                {
                    this.lblOffline.Visible = !online;
                    this.lblOnline.Visible = online;
                }
            }
        }

        private void salirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var dg = MessageBox.Show(
                "¿Está seguro que desea cerrar la aplicación?",
                "Cerrando Aplicación",
                MessageBoxButtons.YesNoCancel,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);

            if (dg != DialogResult.Yes)
            {
                e.Cancel = true;
            }
        }

        private void nuevoLoteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderDialog = new FolderBrowserDialog()
            {
                SelectedPath = "C:\\temp\\despachos\\lote",
                Description = "Seleccione el directorio en donde se encuentran las imágenes.",
                ShowNewFolderButton = false
            };

            var dialogResult = folderDialog.ShowDialog();
            if (dialogResult == DialogResult.Cancel)
                return;

            var nuevoLote = new EditarDespachos()
            {
                MdiParent = this,
                FolderPath = folderDialog.SelectedPath
            };

            nuevoLote.WindowState = FormWindowState.Maximized;
            nuevoLote.Show();

        }

        private void verDespachosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (VerDespachosForm == null)
                VerDespachosForm = new VerDespachos()
                {
                    MdiParent = this
                };

            VerDespachosForm.Show();
            VerDespachosForm.WindowState = FormWindowState.Maximized;
        }

    }
}
